﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Community.CsharpSqlite.Entity;

namespace Community.CsharpSqlite
{
    class Helper
    {



        /*
** The following macros are used to suppress compiler warnings and to
** make it clear to human readers when a function parameter is deliberately
** left unused within the body of a function. This usually happens when
** a function is called via a function pointer. For example the
** implementation of an SQL aggregate step callback may not use the
** parameter indicating the number of arguments passed to the aggregate,
** if it knows that this is enforced elsewhere.
**
** When a function parameter is not used at all within the body of a function,
** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
** However, these macros may also be used to suppress warnings related to
** parameters that may or may not be used depending on compilation options.
** For example those parameters only used in assert() statements. In these
** cases the parameters are named as per the usual conventions.
*/
        //#define Helper.UNUSED_PARAMETER(x) (void)(x)
        public static void UNUSED_PARAMETER<T>(T x)
        {
        }

        //#define Helper.UNUSED_PARAMETER2(x,y) Helper.UNUSED_PARAMETER(x),Helper.UNUSED_PARAMETER(y)
        public static void UNUSED_PARAMETER2<T1, T2>(T1 x, T2 y)
        {
            UNUSED_PARAMETER(x);
            UNUSED_PARAMETER(y);
        }

      
        //#define Helper.ENC(db) ((db)->aDb[0].pSchema->enc)
        /// <summary>
        ///  A macro to discover the encoding of a database.
        /// </summary>
        public static byte ENC(sqlite3 db)
        {
            return db.aDb[0].pSchema.enc;
        }


        /*
** These macros can be used to test, set, or clear bits in the
** Expr.flags field.
*/
        //#define Helper.ExprHasProperty(E,P)     (((E)->flags&(P))==(P))
        public static bool ExprHasProperty(Expr E, int P)
        {
            return (E.flags & P) == P;
        }

        //#define Helper.ExprHasAnyProperty(E,P)  (((E)->flags&(P))!=0)
        public static bool ExprHasAnyProperty(Expr E, int P)
        {
            return (E.flags & P) != 0;
        }

        //#define Helper.ExprSetProperty(E,P)     (E)->flags|=(P)
        public static void ExprSetProperty(Expr E, int P)
        {
            E.flags = (ushort)(E.flags | P);
        }

        //#define Helper.ExprClearProperty(E,P)   (E)->flags&=~(P)
        public static void ExprClearProperty(Expr E, int P)
        {
            E.flags = (ushort)(E.flags & ~P);
        }


        /*
** These macros can be used to test, set, or clear bits in the
** Db.pSchema->flags field.
*/
        //#define Helper.DbHasProperty(D,I,P)     (((D)->aDb[I].pSchema->flags&(P))==(P))
        public static bool DbHasProperty(sqlite3 D, int I, ushort P)
        {
            return (D.aDb[I].pSchema.flags & P) == P;
        }

        //#define DbHasAnyProperty(D,I,P)  (((D)->aDb[I].pSchema->flags&(P))!=0)
        //#define Helper.DbSetProperty(D,I,P)     (D)->aDb[I].pSchema->flags|=(P)
        public static void DbSetProperty(sqlite3 D, int I, ushort P)
        {
            D.aDb[I].pSchema.flags = (ushort)(D.aDb[I].pSchema.flags | P);
        }

        //#define Helper.DbClearProperty(D,I,P)   (D)->aDb[I].pSchema->flags&=~(P)
        public static void DbClearProperty(sqlite3 D, int I, ushort P)
        {
            D.aDb[I].pSchema.flags = (ushort)(D.aDb[I].pSchema.flags & ~P);
        }



        /// <summary>
        /// The name of the schema table.
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public static string SchemaTable(int x)
        //#define Helper.SchemaTable(x)  ((!Const.OMIT_TEMPDB)&&(x==1)?Const.TEMP_MASTER_NAME:Const.MASTER_NAME)
        {
            return ((Const.OMIT_TEMPDB == 0) && (x == 1) ? Const.TEMP_MASTER_NAME : Const.MASTER_NAME);
        }

    }
}
